/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.quantum.jbencoder.types;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * Implement Bencoded Integer type
 * @author g073025
 */
public class BencodedInteger extends BencodedPrimitiveType{
    private final byte prefix = 'i';
    private long value;
    

    /**
     * write a prefix according to Bencoded type specification (i for integer)
     * @param os
     * @throws IOException 
     */
    @Override
    protected void writePrefix(OutputStream os) throws IOException{
            os.write(prefix);        
    }

    /**
     * write value
     * @param os
     * @throws IOException 
     */
    @Override
    protected void writeValue(OutputStream os) throws IOException {
        os.write(Long.toString(getValue()).getBytes(charset));
    }

    /**
     * write suffix
     * @param os
     * @throws IOException 
     */
    @Override
    protected void writeSuffix(OutputStream os) throws IOException {
        os.write(suffix);
    }

    /**
     * @return the value
     */
    public long getValue() {
        return value;
    }

    /**
     * @param value the value to set
     */
    public void setValue(long value) {
        this.value = value;
    }

    @Override
    public void deserialize(InputStream is) throws IOException {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
}
